# test non-event objects and methods
use PlPN qw(PN);
use PlPN::Scintilla;

my $new = PN->NewDocument('perl');

#
# Text retrieval and modification
#

$new->SetText(<<TEXT);
use Test;
\$test = 'test';
print \$test;
TEXT
my $gotback = $new->GetText;
$new->SetSavePoint;
my $line = $new->GetLine(1);
$new->ReplaceSel("#!perl -w\n");
$new->SetReadOnly(1);
my $ro = $new->GetReadOnly;
$new->SetReadOnly(0);
my $tr = $new->GetTextRange(5,25);

# Switching to the MessageBox window causes the Scintilla control to lex
#PlPN->alert('let it lex so we can get styled text');

my $st = $new->GetStyledText(5,25);
my $styled = join(':', @$st);
$new->Allocate(0xffff);
$new->AddText(qq(my \$var = "\0";\n));
$new->AddStyledText([
	1  => "#This is an error\n",
	6 => qq(#"This is a string"\n),
]);
$new->AppendText("1;	# end with a true value\n");
$new->InsertText("# this is some testing stuff\n", 10);
my $char = $new->GetCharAt(42);

#PlPN->alert('let it lex so we can get styled char');

my $style = $new->GetStyleAt(42);
my $putback = $new->GetText;
$new->ClearDocumentStyle;
$new->ClearAll;
$new->AddText($putback);
my $sb = $new->GetStyleBits;
$new->SetStyleBits($sb);

#$line=~s/([\0-\x{1f}])/sprintf("x'%02X'", ord $1)/ge;

=pod

PlPN->alert(<<INFO);
PlPN::Document Scintilla text retrieval functions:

Text: [$gotback]
Line: [$line]
Read-only: [$ro]
Text Range: [$tr]
Styled Text: [$styled]
Char: [$char]
Style: [$style]
Style Bits: [$sb]
INFO

=cut

#
# Searching and replacing
#

#use constant SCFIND_WHOLEWORD => 2;
#use constant SCFIND_MATCHCASE => 4;
#use constant SCFIND_WORDSTART => 0x00100000;
#use constant SCFIND_REGEXP    => 0x00200000;
#use constant SCFIND_POSIX     => 0x00400000;

use PlPN::Scintilla qw(:find);

my ($fs, $fe) = $new->FindText('this', 5, 25);
$new->SearchAnchor;
my $sp = $new->SearchPrev('this', SCFIND_MATCHCASE);
$new->SearchAnchor;
my $sn = $new->SearchNext('error', SCFIND_WHOLEWORD);
$new->TargetFromSelection;
my $ts1 = $new->GetTargetStart;
my $te1 = $new->GetTargetEnd;
$new->SetTargetStart(0);
$new->SetTargetEnd(length($putback));
$new->SearchInTarget('This', SCFIND_MATCHCASE);
my $ts2 = $new->GetTargetStart;
my $te2 = $new->GetTargetEnd;
my $sf1 = $new->GetSearchFlags;
$new->SetSearchFlags(SCFIND_WHOLEWORD);
my $sf2 = $new->GetSearchFlags;
$new->ReplaceTarget('Tihs');
#$new->SetTargetStart(0);
#$new->SetTargetEnd(length($putback));
my $x = $new->SearchInTarget('([ih]+)', SCFIND_POSIX);	# why is this not working?
my $ts3 = $new->GetTargetStart;
my $te3 = $new->GetTargetEnd;
my $sf3 = $new->GetSearchFlags;
$new->ReplaceTargetRE('\\2\\1');	# can't test this until RE search is working
my $tag = $new->GetTag('\\1');	# can't test this until RE search is working


(my $textbase = $putback)=~s/\0/[NUL]/;

PlPN->alert(<<INFO);
PlPN::Document Scintilla search functions:

$textbase

FindText: $fs-$fe
SearchNext: $sn
SearchPrev: $sp
Target 1: $ts1-$te1
Flags 1: $sf1
Target 2: $ts2-$te2
Flags 2: $sf2
X: $x
Target 3: $ts3-$te3
Flags 3: $sf3
INFO

# set save point so PN doesn't ask about saving
$new->SetSavePoint;
$new->Close();

=pod

# list of possible messages
# may need to generate some constants for these

	$result = $document->SendEditorMessageI($msg, $wParam, $lParam);

	$result = $document->SendEditorMessageS($msg, $wParam, $strParam);

=cut
